<include file="Public:head" />



<div class="table_box">
  <!-- 筛选 -->
  <form class="layui-form" id="search" action="__APP__/typesx/list_" method="get" style="margin-bottom: 20px;">
      <div class="layui-input-inline">
        <input type="text" name="name_" lay-verify="name_" autocomplete="off" placeholder="名称搜索" class="layui-input" style="width:200px;" value="{$name_}">
      </div>
      <div class="layui-input-inline">
        <select name="type_id" id="type_id">
          <option value="">二级分类</option>
          <foreach name="group" key="k" item="v">
            <option value="{$v.id}">{$v.name}</option>
          </foreach>
        </select>    

      </div>
      <script type="text/javascript">
        $("#name_").val("{$name_}");
        $("#type_id").val("{$type_id}");
        /*function fomrReset()
        {
            document.getElementById("search").reset();
        }*/
        
      </script>

      <div class="layui-input-inline" style="margin-left: 10px;">
        <button class="layui-btn " type="submit">搜索</button>
      </div>
      
  </form>

  <!-- 操作按钮 -->
  <div class="layui-input-inline" >
    <button class="layui-btn layui-btn-sm layui-btn-normal"  onclick="doedit(1)">
      <i class="layui-icon">&#xe608;</i>
      添加顶级筛选
    </button>
   
  </div>


  <!-- 表格 -->
  <table class="layui-table layui-table-wen" >
    <colgroup>
      <col width="100">
      <col>
      <col>
      <col>
      <col>
     
      <col width="200">
      <col width="120">
    </colgroup>
    <thead>
      <tr>
        <th>ID</th>
        <th>筛选名称</th>
        <th>所属二级分类</th>
      
        <th>状态</th>
        <th>添加时间</th>
        
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>
      <foreach name="list" key="k" item="v">
        <tr>
          <td>{$v.id}</td>
          <td>{$v.name}</td>
          <td>{$v.type_id_txt}</td>
         
          <td>
            <if condition="$v.status == 1">
              开启
            <else/>
              关闭
            </if>

          </td>
          <td>{$v.ctime}</td>
          <td>
            <a  class="wen_a" onclick="doedit(2,{$v.id},'{$v.name}','{$v.pid}','{$v.status}','{$v.type_id}','{$v.type_id_txt}')">编辑</a> 
            <div class="wen_a_fenge"></div>
            <a  class="wen_a" onclick="del({$v.id})">删除</a> 
            
            <if condition="$v.pid == 0">
              <div class="wen_a_fenge"></div>
              <a  class="wen_a" onclick="doedit(3,{$v.id},'{$v.name}','{$v.pid}','{$v.status}','{$v.type_id}')">添加子筛选</a> 
            </if>
          </td>
        </tr>
        <!-- 循环中循环 -->
        <foreach name="v['data']" key="kk" item="vv">
          <tr>
          <td>{$vv.id}</td>
          <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|—— {$vv.name}</td>
          <td>{$v.type_id_txt}</td>
          <td>
            <if condition="$vv.status == 1">
              开启
            <else/>
              关闭
            </if>
          </td>
          <td>{$vv.ctime}</td>
          <td>
            <a  class="wen_a" onclick="doedit(4,{$vv.id},'{$vv.name}','{$vv.pid}','{$vv.status}','{$v.type_id}')">编辑</a> 
            <div class="wen_a_fenge"></div>
            <a  class="wen_a" onclick="del({$vv.id})">删除</a> 
      
          </td>
        </tr>
        </foreach>
  
      </foreach>
      
    </tbody>
  </table>

</div>

<include file="Public:foot" />








<!-- ---------------------------------------------------------------- -->








<script>
//添加顶级
function doedit (type,id,name,pid,status,type_id,type_id_txt) {
  $('#name').val(name);
  if(type == 1){
    var txt = '添加一级筛选'; 
  }else if(type == 2){
    var txt = '编辑一级筛选'; 
    // alert(name);
      
  }else if(type == 3){
    var txt = '添加二级筛选';
    
    $('#type_id_box').attr('display','none');
  }else if(type == 4){
    var txt = '编辑二级筛选'; 
  }
  layui.use(['layer','form'], function() {
    var form = layui.form;
    var layer = layui.layer;

    layer.open({
      type: 1,
      title: txt,
      area: ['500px', '400px'] ,
      shadeClose: true, 
      content: $('#box').html()
    })
    if(type == 1){
      
    }else if(type == 2){
      $('#type_id').val(type_id);
      $('#status').val(status);
      $('#name').val(name);

    }else if(type == 3){
      $('#type_id_box').hide();
      $('#type_id').val(type_id);
      $('#type_id_ture').val(type_id);
    }else if(type == 4){
      $('#type_id_box').hide();
      $('#type_id').val(type_id);
      $('#name').val(name);
      $('#type_id_ture').val(type_id);
    }
  
      $('.editId').val(id);
      $('.typeId').val(type);
  
      form.render();//渲染

  })
}

//确定-提交
function sub(){
  var name = $('#name').val();
  var status = $('#status').val();
  var type_id = $('#type_id').val();
 // alert(status);
  if(name == ''){
      layer.msg('分类名不能为空',{
        time:900  ,           //时间
      });
      return false;
  }
  // if(type_id == null){
  //     layer.msg('所属二级分类不能为空',{
  //       time:900  ,           //时间
  //     });
  //     return false;
  // }
  if(status == ''){
      layer.msg('状态不能为空',{
        time:900  ,           //时间
      });
      return false;
  }
  
  $.ajax({
      type:"get",
      url:"__APP__/typesx/add_edit",
      data:$("#add_edit").serialize(),

      success:function(data){
        alert(data);
        // returnInfo(data);

      }        
  })//ajax结束
}
//取消-提交

//删除
function del(id){

  layer.confirm('确定删除这个分类吗？', {
    btn: ['确定'], //按钮
    title: '系统提示',
    shadeClose: true
  }, function(){  //确定
    $.ajax({
        type:"get",
        url:"__APP__/typesx/del?id="+id,
        

        success:function(data){
          console.log(data);
          // alert(data);
          returnInfo(data);

        }        
    })//ajax结束
  })


}

</script>










<!-- ---------------------------------------------------------------- -->










<!-- 添加顶级筛选 -->
<script id="box">
  <style>
    .layui-input-item{
      margin-bottom: 15px;
    }
  </style>
  <form class="layui-form" id="add_edit" action="" style="margin:15px;">
    <!-- 隐藏域 -->
    <input type="hidden" name="id" class="editId">
    <input type="hidden" name="type" class="typeId">
    <input type="hidden" name="type_id_ture" id="type_id_ture">
    <!-- 文本输入 -->
    <div class="layui-form-item" style="">
      <label class="layui-form-label" style="width:100px"><span style="color:red">*</span> 筛选名称</label>
      <div class="layui-input-inline">
        <input style="width:300px" type="text" id="name" name="name" lay-verify="name" autocomplete="off" placeholder="请输入分类名称" class="layui-input" >
      </div>
    </div>
    <!-- 下拉选框 -->
    <div class="layui-form-item" id="type_id_box">
      <label class="layui-form-label" style="width:100px"><span style="color:red">*</span> 所属二级分类</label>
      <div class="layui-input-inline" style="width:300px">
        <select name="type_id" id="type_id" >
           
          <foreach name="group" key="k" item="v">
            <option value="{$v.id}">{$v.name}</option>
          </foreach>
        </select>
      </div>
    </div> 
    <!-- 下拉选框 -->
    <div class="layui-form-item">
      <label class="layui-form-label" style="width:100px"><span style="color:red">*</span> 状态</label>
      <div class="layui-input-inline" style="width:300px">
        <select name="status" id="status" >
          <option value="1">开启</option>
          <option value="2">关闭</option>
        </select>
      </div>
    </div> 
 
    <!-- 按钮 -->
    <div class="layui-form-item" style="margin:20px auto;width:150px;">
      <a class="layui-btn" onclick="sub()">确定</a>
      <a class="layui-btn layui-btn-primary" onclick="close_()">取消</a>
    </div>
  </form>
</div>
</script>
